#include<func.h>

void cleanfunc(void *p)
{
    printf("i am cleanup %ld\n",(long)p);
}

void *pthead_func(void *p)
{
    pthread_cleanup_push(cleanfunc,(void*)1);
    pthread_cleanup_push(cleanfunc,(void*)2);
    printf("i am child\n");
    pthread_cleanup_pop(0);
    pthread_cleanup_pop(0);
    printf("you cant see me\n");

    return (void*)2;

}

int main()
{
    pthread_t pthid;
    int ret=pthread_create(&pthid,NULL,pthead_func,(void*)1);
    THREAD_ERR_CHECK(ret,"pthread_create")
    pthread_cancel(pthid);
    THREAD_ERR_CHECK(ret,"pthread_cance")
    long pthread_return;
    pthread_join(pthid,(void **)&pthread_return);//如果子线程没有被终止则返回2，否则返回-1
    printf("i am main,pthread_return=%ld\n",pthread_return);
    return 0;
}